﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using mitasoft.Web.Business;
using mitasoft.Web.DAL.Model;
using MySite2.Models;
using MySite2.Services;
using MySite2.ViewModel;


namespace MySite2.Controllers
{
    public class HomeController : BaseController
    {

        //
        // GET: /Home/
        //[OutputCache(Duration = 600)]
        public ActionResult Index()
        {
            try
            {
                IndexModel indexModel = new IndexModel();
                SocialBusiness socialBusiness = new SocialBusiness();

                // get social info
                indexModel.TwitterMessages = socialBusiness.GetTwitterMessages(7);
                indexModel.BlogPosts = socialBusiness.GetBlogPosts(10);

                return View(indexModel);
            }
            catch (Exception ex)
            {
                Logger.Instance.Info(ex.ToString());
                return RedirectToAction("ErrorOnSite", "BaseController");
            }
        }

        public ActionResult GetTop3Books()
        {
            BooksViewModel booksViewModel = new BooksViewModel();
            
            var books = booksViewModel.GetTop3Books()
                .Select( b=> new { b.Title, b.CoverUrl })
                .ToList();

            return Json(books, JsonRequestBehavior.AllowGet);
        }
    }
}
